<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<script src="http://code.jquery.com/jquery-latest.js"></script>
		<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.12.0.css" type="text/css" media="screen" />
		<script type="text/javascript" src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script>
		<script type="text/javascript" src="../build/astrochart.js"></script>	
		
		<script>			
			window.onload = function( ) {	
				
				test( "getPointPosition", function( ) {						
					deepEqual(astrology.utils.getPointPosition(10,10,10,0), {x:0, y:10});	
					deepEqual(astrology.utils.getPointPosition(10,10,10,90), {x:10, y:20});
					deepEqual(astrology.utils.getPointPosition(10,10,10,180), {x:20, y:10});
					deepEqual(astrology.utils.getPointPosition(10,10,10,270), {x:10, y:0});
					deepEqual(astrology.utils.getPointPosition(10,10,10,360), {x:0, y:10});
					deepEqual(astrology.utils.getPointPosition(10,10,10,450), {x:10, y:20});													
				});	
				
				test( "placePointsInCollision", function( ) {	
					
					var p1, p2;					
					
					p1 = {name:'Sun', pointer:1, angle:1};
					p2 = {name:'Mercury', pointer:359, angle:1};					
					astrology.utils.placePointsInCollision(p1, p2);					
					deepEqual(p1, {name:'Sun', pointer:1, angle:2});
					deepEqual(p2, {name:'Mercury', pointer:359, angle:0});
					
					p1 = {name:'Mercury', pointer:359, angle:1};
					p2 = {name:'Sun', pointer:1, angle:1};										
					astrology.utils.placePointsInCollision(p1, p2);					
					deepEqual(p1, {name:'Mercury', pointer:359, angle:0});
					deepEqual(p2, {name:'Sun', pointer:1, angle:2});
					
					p1 = {name:'Sun', pointer:10, angle:10};
					p2 = {name:'Mercury', pointer:20, angle:10};					
					astrology.utils.placePointsInCollision(p1, p2);					
					deepEqual(p1, {name:'Sun', pointer:10, angle:9});
					deepEqual(p2, {name:'Mercury', pointer:20, angle:11});
																		
				});
				
				test( "isCollision", function( ) {
					 equal(astrology.utils.isCollision({x:10, y:10, r:5}, {x:10, y:10, r:5}), true);
					 
					 equal(astrology.utils.isCollision({x:10, y:10, r:5}, {x:20, y:10, r:5}), true);
					 equal(astrology.utils.isCollision({x:10, y:10, r:5}, {x:21, y:10, r:5}), false);
					 
					 equal(astrology.utils.isCollision({x:10, y:10, r:5}, {x:10, y:20, r:5}), true);
					 equal(astrology.utils.isCollision({x:10, y:10, r:5}, {x:10, y:21, r:5}), false);
					 
					 equal(astrology.utils.isCollision({x:10, y:10, r:5}, {x:20, y:10, r:10}), true);
				});
										
				test( "comparePoints", function( ) {
											
					var point1, poit2;						
														
					point1 = {angle:10}
					point2 = {angle:20}																				
					equal( astrology.utils.comparePoints( point1, point2 ), -10 );	
					
					point1 = {angle:20}
					point2 = {angle:20}																				
					equal( astrology.utils.comparePoints( point1, point2 ), 0 );
					
					point1 = {angle:30}
					point2 = {angle:20}																				
					equal( astrology.utils.comparePoints( point1, point2 ), 10 );
					
					point1 = {angle:0}
					point2 = {angle:1}																				
					equal( astrology.utils.comparePoints( point1, point2 ), -1 );
					
					point1 = {angle:259.99}
					point2 = {angle:0}																				
					equal( astrology.utils.comparePoints( point1, point2 ), 259.99 );												
				});	
				
				test( "assemble", function( ) {	
																				
					astrology.DEBUG = true;
					astrology.COLLISION_RADIUS = 10;
					
					var locatedPoints, universe, point, planetRadius;					
					
					locatedPoints = [];					
					universe = {cx:0, cy:0, r:100}									
					planetRadius = astrology.COLLISION_RADIUS;
																															
					point = {name:"Point1", x:100, y:0, r:planetRadius, angle:180}														
					locatedPoints = astrology.utils.assemble(locatedPoints, point, universe);
																		
					point = {name:"Point2", x:100, y:0, r:planetRadius, angle:180}														
					locatedPoints = astrology.utils.assemble(locatedPoints, point, universe);
					
					point = {name:"Point3", x:100, y:0, r:planetRadius, angle:180}														
					locatedPoints = astrology.utils.assemble(locatedPoints, point, universe);
					
					point = {name:"Point4", x:100, y:0, r:planetRadius, angle:180}														
					locatedPoints = astrology.utils.assemble(locatedPoints, point, universe);
					
					point = {name:"Point5", x:100, y:0, r:planetRadius, angle:180}														
					locatedPoints = astrology.utils.assemble(locatedPoints, point, universe);
					
					point = {name:"Point6", x:100, y:0, r:planetRadius, angle:180}														
					locatedPoints = astrology.utils.assemble(locatedPoints, point, universe);
					
					point = {name:"Point7", x:100, y:0, r:planetRadius, angle:180}														
					locatedPoints = astrology.utils.assemble(locatedPoints, point, universe);
					
					point = {name:"Point8", x:100, y:0, r:planetRadius, angle:180}														
					locatedPoints = astrology.utils.assemble(locatedPoints, point, universe);
					
					point = {name:"Point9", x:100, y:0, r:planetRadius, angle:180}														
					locatedPoints = astrology.utils.assemble(locatedPoints, point, universe);
					
					point = {name:"Point10", x:100, y:0, r:planetRadius, angle:180}														
					locatedPoints = astrology.utils.assemble(locatedPoints, point, universe);
					
					console.log( locatedPoints )
														
					equal( locatedPoints.length, 10 );												
				});	
				
				test( "assemble2", function( ) {
										
					var universe = {cx:0, cy:0, r:100};					
					var collisionRadius = 10;
					var angle, planetPosition, sun, mercury, venus, result, locatedPoints;
					
					//---
					angle = 0;
					planetPosition = astrology.utils.getPointPosition(universe.cx, universe.cy, universe.r, angle);
					sun = {name:"Sun", x:planetPosition.x, y:planetPosition.y, r:collisionRadius, angle:angle};					
					deepEqual(astrology.utils.assemble([], sun, universe), [sun]);
															
					//---										
					angle = 90;
					planetPosition = astrology.utils.getPointPosition(universe.cx, universe.cy, universe.r, angle);					
					mercury = {name:"Mercury", x:planetPosition.x, y:planetPosition.y, r:collisionRadius, angle:angle};																										
																											
					locatedPoints = astrology.utils.assemble([sun], mercury, universe);
					equal(locatedPoints[0].angle, 0); 
					equal(locatedPoints[1].angle, 90);
					
					//---
					angle = 2;
					planetPosition = astrology.utils.getPointPosition(universe.cx, universe.cy, universe.r, angle);					
					mercury = {name:"Mercury", x:planetPosition.x, y:planetPosition.y, r:collisionRadius, angle:angle};																										
																											
					locatedPoints = astrology.utils.assemble([sun], mercury, universe);
					equal( parseInt(locatedPoints[0].angle,10), 7); 
					equal(parseInt(locatedPoints[1].angle,10), 355);
					equal(locatedPoints.length, 2);
										
					//---
					angle = 1;
					planetPosition = astrology.utils.getPointPosition(universe.cx, universe.cy, universe.r, angle);					
					venus = {name:"Venus", x:planetPosition.x, y:planetPosition.y, r:collisionRadius, angle:angle};																										
																											
					locatedPoints = astrology.utils.assemble([sun, mercury], venus, universe);
					
					equal( locatedPoints[0].name, "Mercury"); 
					equal( parseInt(locatedPoints[0].angle,10), 1);
					
					equal( locatedPoints[1].name, "Sun");
					equal(parseInt(locatedPoints[1].angle,10), 13);
					
					equal( locatedPoints[2].name, "Venus");
					equal(parseInt(locatedPoints[2].angle,10), 349);
										
					equal(locatedPoints.length, 3);					
				});
				
																																															
			};// onload
		</script>
	</head>
	<body>
		<h1 id="qunit-header">chart.js tests</h1>
		<h2 id="qunit-banner"></h2>
		<div id="qunit-testrunner-toolbar"></div>
		<h2 id="qunit-userAgent"></h2>
		<ol id="qunit-tests"></ol>
		<div id="qunit-fixture">
			test markup, will be hidden
		</div>
	</body>
</html>